import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import * as path from 'path'
export default defineConfig(({ command, mode }) => {
  // command 运行标记 build  serve
  return {
    base: './',
    plugins: [vue()],
    resolve: {
      alias: [
        {
          find: '@',
          replacement: path.resolve(__dirname, './src'),
        },
      ],
    },
    css: {
      preprocessorOptions: {
        less: {
          modifyVars: {
            hack: `true; @import (reference) "${path.resolve(
              'src/publicStyle/varLess.less'
            )}";`,
          },
          javascriptEnabled: true,
        },
      },
    },
    server: {
      cors: true,
      host: '0.0.0.0',
      port: 8848,
      open: true,
      proxy: {
        '/api': {
          target: loadEnv(mode, process.cwd()).VITE_BASE_URL,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ''),
        },
      },
    },
  }
})
